//
//  ZGView.m
//  扫码
//
//  Created by 鲍志刚 on 16/4/13.
//  Copyright © 2016年 鲍志刚. All rights reserved.
//

#import "ZGView.h"

@interface ZGView ()

@property (nonatomic, strong) NSArray *array;

@end

@implementation ZGView

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    
  
    
     NSArray *data = @[@100, @375, @0, @486, @195, @337];
    
    //创建路径
    //设置圆心
    CGPoint centerP = CGPointMake(rect.size.width / 2, rect.size.height/2);
    
    //设置半径
    CGFloat radius = MIN(rect.size.width, rect.size.height)/2;
    
    CGFloat start = 0;
    CGFloat end = 0;
    
    for (int i = 0; i < data.count; i++) {
        
        end = ([data[i] floatValue]/(100+375+486+195+337)) * 2 * M_PI + start;
        
        UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:centerP radius:radius startAngle:start endAngle:end clockwise:YES];
        
        [path addLineToPoint:centerP];
        
        [[self randomColor] set];
        
        [path fill];
        
        start = end;

    }
    
 
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self setNeedsDisplay];
}



- (UIColor *) randomColor
{
    //随机红绿蓝
    CGFloat red = arc4random_uniform(256)/255.f;
    CGFloat green = arc4random_uniform(256)/255.f;
    CGFloat blue = arc4random_uniform(256)/255.f;
    
    UIColor * color = [UIColor colorWithRed:red green:green blue:blue alpha:1.f];
    
    return color;
}


@end
